Load required libraries.
library(Seurat)
Registered S3 method overwritten by 'data.table':
method from
print.data.table
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
Registered S3 method overwritten by 'spatstat.geom':
method from
print.boxx cli
Attaching SeuratObject
Warning message:
R graphics engine version 14 is not supported by this version of RStudio. The Plots tab will be disabled until a newer version of RStudio is installed.
library(tidyverse)
Registered S3 methods overwritten by 'dbplyr':
method from
print.tbl_lazy
print.tbl_sql
[30m── [1mAttaching packages[22m ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.1 ──[39m
[30m[32m✓[30m [34mggplot2[30m 3.3.5 [32m✓[30m [34mpurrr [30m 0.3.4
[32m✓[30m [34mtibble [30m 3.1.6 [32m✓[30m [34mdplyr [30m 1.0.7
[32m✓[30m [34mtidyr [30m 1.1.4 [32m✓[30m [34mstringr[30m 1.4.0
[32m✓[30m [34mreadr [30m 2.1.1 [32m✓[30m [34mforcats[30m 0.5.1[39m
[30m── [1mConflicts[22m ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
[31mx[30m [34mdplyr[30m::[32mfilter()[30m masks [34mstats[30m::filter()
[31mx[30m [34mdplyr[30m::[32mlag()[30m masks [34mstats[30m::lag()[39m
Load Seurat object.
load("/Volumes/Bud_SSD/20210505-seurat/all-aggr-neighbors.Robj")
We settled on 5 clusters.
load("/Volumes/Bud_SSD/20210505-seurat/all-aggr-cluster-iters/cluster-per-cell-all-aggr-clust-5.Robj")
all.aggr$cluster <- all.aggr.active.ident
Idents(all.aggr) <- all.aggr.active.ident
tsne.whole <- data.frame(all.aggr@reductions$tsne@cell.embeddings, all.aggr$embryo.id, all.aggr$genotype, all.aggr$cluster)
colnames(tsne.whole) <- c("tsne.1", "tsne.2", "embryo.id", "genotype", "cluster")
head(tsne.whole)
tsne.whole$genotype <- factor(x = tsne.whole$genotype, levels = c("Flox", "FIN"))
Generate positions and labels for each cluster.
tsne.label <- tsne.whole %>% group_by(cluster) %>% summarize(tsne.1 = median(tsne.1), tsne.2 = median(tsne.2))
By genotype.
genotype.tsne <- ggplot() +
geom_point(data = sample(tsne.whole), mapping = aes(x = tsne.1, y = tsne.2, color = genotype), shape = 20, size = 1, stroke = 0, alpha = 1) +
scale_color_manual(values = c("royalblue", "indianred"), labels = c("Nipbl Flox/+", "Nipbl FIN/+")) +
guides(color = guide_legend(override.aes = list(size = 3.5))) +
labs(title = "Whole, Nipbl Flox/+ & FIN/+", x = "t-SNE 1", y = "t-SNE 2", color = "Genotype") +
theme_classic(base_size = 7) +
theme(axis.line = element_blank(), axis.ticks = element_blank(), axis.text = element_blank(), legend.key.size = unit(7, "pt"), plot.title = element_text(hjust = 0.5))
genotype.tsne
ggsave(plot = genotype.tsne, filename = "/Volumes/Bud_SSD/20210505-seurat/tsne-by-genotype-all-aggr.png", device = "png", units = "in", width = 6.5, height = 4.5)
library(scales)
Attaching package: ‘scales’
The following object is masked from ‘package:purrr’:
discard
The following object is masked from ‘package:readr’:
col_factor
Get colors for each cluster. We need 11 colors.
show_col(hue_pal()(12))
hue_pal()(12)
[1] "#F8766D" "#DE8C00" "#B79F00" "#7CAE00" "#00BA38" "#00C08B" "#00BFC4" "#00B4F0" "#619CFF" "#C77CFF" "#F564E3" "#FF64B0"
See within genotype.
flox.tsne <- ggplot() +
geom_point(data = sample(tsne.whole %>% filter(genotype == "Flox")), mapping = aes(x = tsne.1, y = tsne.2, color = embryo.id), shape = 20, size = 1, stroke = 0) +
scale_color_manual(labels = c("EP1", "EP2", "EP3", "EP4", "EP5"), values = hue_pal()(12)[c(1, 7, 3, 9, 5)]) +
labs(title = "Whole, Nipbl Flox/+", x = "t-SNE 1", y = "t-SNE 2", color = "Embryo\nPair") +
guides(color = guide_legend(override.aes = list(size = 3.5))) +
theme_classic(base_size = 7) +
theme(axis.line = element_blank(), axis.ticks = element_blank(), axis.text = element_blank(), legend.key.size = unit(7, "pt"), plot.title = element_text(hjust = 0.5))
flox.tsne
ggsave(plot = flox.tsne, filename = "/Volumes/Bud_SSD/20210505-seurat/tsne-by-embryo-flox-all-aggr.png", device = "png", units = "in", width = 6.5, height = 4.5)
fin.tsne <- ggplot() +
geom_point(data = sample(tsne.whole %>% filter(genotype == "FIN")), mapping = aes(x = tsne.1, y = tsne.2, color = embryo.id), shape = 20, size = 1, stroke = 0) +
scale_color_manual(labels = c("EP6", "EP7", "EP8", "EP9", "EP10", "EP11"), values = hue_pal()(12)[c(2, 8, 4, 10, 6, 12)]) +
labs(title = "Whole, Nipbl FIN/+", x = "t-SNE 1", y = "t-SNE 2", color = "Embryo\nPair") +
guides(color = guide_legend(override.aes = list(size = 3.5))) +
theme_classic(base_size = 7) +
theme(axis.line = element_blank(), axis.ticks = element_blank(), axis.text = element_blank(), legend.key.size = unit(7, "pt"), plot.title = element_text(hjust = 0.5))
fin.tsne
ggsave(plot = fin.tsne, filename = "/Volumes/Bud_SSD/20210505-seurat/tsne-by-embryo-fin-all-aggr.png", device = "png", units = "in", width = 6.5, height = 4.5)
Make new directory.
dir.create('/Volumes/Bud_SSD/20210505-seurat/all-aggr-clust-5')
tsne by cluster
cluster.tsne <- ggplot() +
geom_point(data = sample(tsne.whole), mapping = aes(x = tsne.1, y = tsne.2, color = cluster), shape = 20, size = 1, stroke = 0) +
geom_text(data = tsne.label, mapping = aes(x = tsne.1, y = tsne.2, label = cluster), size = 3.5) +
labs(title = "Whole, Nipbl Flox/+ & FIN/+", x = "t-SNE 1", y = "t-SNE 2", color = "Cluster") +
guides(color = guide_legend(override.aes = list(size = 3.5))) +
theme_classic(base_size = 7) +
theme(axis.line = element_blank(), axis.ticks = element_blank(), axis.text = element_blank(), legend.key.size = unit(7, "pt"), plot.title = element_text(hjust = 0.5))
cluster.tsne
ggsave(plot = cluster.tsne, filename = "/Volumes/Bud_SSD/20210505-seurat/all-aggr-clust-5/tsne-by-cluster-all-aggr-clust-5.png", device = "png", units = "in", width = 6.5, height = 4.5)
Get colors for each cluster. We need 11 colors.
show_col(hue_pal()(5))
hue_pal()(5)
[1] "#F8766D" "#A3A500" "#00BF7D" "#00B0F6" "#E76BF3"
By genotype.
genotype.tsne <- ggplot() +
geom_point(data = sample(tsne.whole), mapping = aes(x = tsne.1, y = tsne.2, color = genotype), shape = 20, size = 1, stroke = 0, alpha = 1) +
scale_color_manual(values = c("royalblue", "indianred"), labels = c("Nipbl Flox/+", "Nipbl FIN/+")) +
geom_density_2d(data = tsne.whole %>% filter(cluster == 2), mapping = aes(x = tsne.1, y = tsne.2), color = "#A3A500", linetype = "solid", size = 1, contour_var = "count", breaks = 1) +
geom_density_2d(data = tsne.whole %>% filter(cluster == 3), mapping = aes(x = tsne.1, y = tsne.2), color = "#00BF7D", linetype = "solid", size = 1, contour_var = "count", breaks = 1) +
geom_label(data = tsne.label, mapping = aes(x = tsne.1, y = tsne.2, label = cluster, fill = cluster), size = 3.5) +
guides(color = guide_legend(override.aes = list(size = 3.5))) +
labs(title = "Whole, Nipbl Flox/+ & FIN/+", x = "t-SNE 1", y = "t-SNE 2", color = "Genotype") +
guides(fill = "none") +
theme_classic(base_size = 7) +
theme(axis.line = element_blank(), axis.ticks = element_blank(), axis.text = element_blank(), legend.key.size = unit(7, "pt"), plot.title = element_text(hjust = 0.5))
genotype.tsne
ggsave(plot = genotype.tsne, filename = "/Volumes/Bud_SSD/20210505-seurat/all-aggr-clust-5/tsne-by-genotype-all-aggr-clust-5.png", device = "png", units = "in", width = 6.5, height = 4.5)
Upload object onto hpc.
scp /Volumes/Bud_SSD/20210505-seurat/tsne-by-genotype-all-aggr.png schea2@hpc3.rcic.uci.edu:/dfs6/pub/schea2/20210505-seurat
scp /Volumes/Bud_SSD/20210505-seurat/tsne-by-embryo-flox-all-aggr.png schea2@hpc3.rcic.uci.edu:/dfs6/pub/schea2/20210505-seurat
scp /Volumes/Bud_SSD/20210505-seurat/tsne-by-embryo-fin-all-aggr.png schea2@hpc3.rcic.uci.edu:/dfs6/pub/schea2/20210505-seurat
scp /Volumes/Bud_SSD/20210505-seurat/all-aggr-clust-5/tsne-by-cluster-all-aggr-clust-5.png schea2@hpc3.rcic.uci.edu:/dfs6/pub/schea2/20210505-seurat/all-aggr-clust-5
scp /Volumes/Bud_SSD/20210505-seurat/all-aggr-clust-5/tsne-by-genotype-all-aggr-clust-5.png schea2@hpc3.rcic.uci.edu:/dfs6/pub/schea2/20210505-seurat/all-aggr-clust-5
save(object = all.aggr, file = "/Volumes/Bud_SSD/20210505-seurat/all-aggr-clust-5/all-aggr-clust-5.Robj")
Warning messages:
1: In readChar(file, size, TRUE) : truncating string with embedded nuls
2: In readChar(file, size, TRUE) : truncating string with embedded nuls
3: In readChar(file, size, TRUE) : truncating string with embedded nuls
4: In readChar(file, size, TRUE) : truncating string with embedded nuls
5: In readChar(file, size, TRUE) : truncating string with embedded nuls
6: In readChar(file, size, TRUE) : truncating string with embedded nuls
7: In readChar(file, size, TRUE) : truncating string with embedded nuls
Upload object onto hpc.
scp /Volumes/Bud_SSD/20210505-seurat/all-aggr-clust-5/all-aggr-clust-5.Robj schea2@hpc3.rcic.uci.edu:/dfs6/pub/schea2/20210505-seurat/all-aggr-clust-5